package com.spring.controller;

import cn.hutool.core.date.DateUtil;
import com.spring.dao.DnDao;
import com.spring.entity.TdDnEntity;
import com.tdengine.conditions.TdQueryLambdaWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 节点探索
 *
 * @author zhangtoa
 */
@RestController
@Slf4j
@RequestMapping("/td")
public class TdEngineController {

    @Resource
    private DnDao dnDao;

    @GetMapping("/query")
    public List<TdDnEntity> query() {
        return dnDao.tdSelectList(new TdQueryLambdaWrapper<TdDnEntity>()
                .max(TdDnEntity::getCpuSystem)
                .interval("1d")
                .sliding("2h")
                .ge(TdDnEntity::getTs, DateUtil.beginOfWeek(new Date()))
                .eq(TdDnEntity::getFqdn, "yc-nsg-d26:6030"));
    }

}
